package leetcode_301_400;

import java.util.ArrayList;
import java.util.List;

public class LeeCode_386 {
    public static void main(String[] args) {
        System.out.println(lexicalOrder(13));
        System.out.println(lexicalOrder(2));
    }
    private static List<Integer> lexicalOrder(int n) {
        List<Integer> ans = new ArrayList<>();
        dfs(ans, 0, n);
        return ans;
    }
    private static void dfs(List<Integer> ans, int now, int n){
        for (int i = 0; i <= 9; i++) {
            int sum = now * 10 + i;
            if (sum > n){
                return;
            }
            if (sum > 0)
                ans.add(sum);
            if (sum > 0)
                dfs(ans, sum, n);
        }
    }
}
